using System;
using System.Data;
using System.Web.UI.WebControls;
using TimeSheet.Protected.View;
using TimeSheetBLL;

namespace TimeSheet.Protected
{
    /// <summary>
    /// Summary description for Activity.
    /// </summary>
    public class Activity : BaseAdminForm
    {
        protected PlaceHolder phViewAll;
        protected PlaceHolder phEntity;

        private void Page_Load(object sender, EventArgs e)
        {
            LoadDefaultLookAndFeel();
            PageTitle = "Timesheet :: Activities";

            LoadEntity();
            LoadGrid();
        }

        private void LoadEntity()
        {
            TimeSheetBLL.Activity act = new TimeSheetBLL.Activity();
            if (RequestedEntityID > 0)
            {
                act.ID = RequestedEntityID;
                BrokerFactory.Fill(act);
            }
            EntityControl cont =
                (EntityControl) LoadControl("View/Model/EditActivity.ascx");
            cont.BoundEntity = act;
            phEntity.Controls.Add(cont);
        }

        private void LoadGrid()
        {
            DataView dv = BrokerFactory.SelectAll(new TimeSheetBLL.Activity()).DefaultView;
            dv.Sort = "activity_name";
            GridControl cont = (GridControl) LoadControl("View/Model/ViewActivities.ascx");
            cont.TableView = dv;
            phViewAll.Controls.Add(cont);
        }

        #region Web Form Designer generated code

        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        #endregion
    }
}